package com.nervenets.web.service;

import com.nervenets.web.entity.SocketMessage;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class WebSocketService {
    @Resource
    private SimpMessagingTemplate simpMessagingTemplate;

    @Async
    public void sendMessage(String topicId, String action, String message) {
        simpMessagingTemplate.convertAndSend("/topic/" + topicId, new SocketMessage(action, message));
    }
}
